package com.zw.cloud.xxljob.controller;

import com.alibaba.fastjson2.JSONObject;
import com.zw.cloud.xxljob.utils.XXLJobUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/xxl-job")
public class XxlJobController {

    @Autowired
    private XXLJobUtils xxlJobUtils;

    @GetMapping("/addJob/{executorHandlerName}/{delaySeconds}")
    //http://localhost:9010/xxl-job/addJob/demoJobHandler/60
    public void addJob(@PathVariable String executorHandlerName,@PathVariable long delaySeconds) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("key","value");
        xxlJobUtils.addJob(executorHandlerName,jsonObject,delaySeconds,"test");
    }

    @GetMapping("/delJob/{jobId}")
    //http://localhost:9010/xxl-job/delJob/5
    public void delJob(@PathVariable String jobId) {
        xxlJobUtils.deleteJob(jobId);
    }
}
